import { defineStore } from 'pinia';

//保存登录用户信息
export const useAuthStore = defineStore('auth', {
  state: () => ({
    userId:-1,
    isAuthenticated: false,
    username: '',
    password:'',
    userType:'',
    email:'',
    phoneNumber:'',
    avatarUrl:''
  }),
  actions: {
    login(userId:number,username:string,password:string,userType:string,email:string,phoneNumber:string,avatarUrl:string) {
      this.userId = userId;
      this.isAuthenticated = true;
      this.username = username;
      this.password = password;
      this.userType = userType;
      this.email = email;
      this.phoneNumber = phoneNumber;
      this.avatarUrl = avatarUrl;
    },
    logout() {
      this.userId = -1;
      this.isAuthenticated = false;
      this.username = '';
      this.password = '';
      this.userType = '';
      this.email = '';
      this.phoneNumber = '';
      this.avatarUrl = ''
    },
  },
  persist:{
    storage: sessionStorage,
}
});